﻿Public Class Auto
  Implements IComparable(Of Auto)

  Private m_tipoOrdinamento As Integer
  Private m_cilindrata As Integer
  Private m_targa As String
  Private m_marca As String

  Public Sub New(ByVal pCilindrata As Integer,
                 ByVal pTarga As String,
                 ByVal pMarca As String)
    m_cilindrata = pCilindrata
    m_targa = pTarga
    m_marca = pMarca
  End Sub

  Public Overloads Function _
     CompareTo(ByVal obj As Auto) _
     As Integer _
     Implements IComparable(Of Auto).CompareTo

    If TypeOf obj Is Auto Then
      Dim temp As Auto = CType(obj, Auto)
      Select Case m_tipoOrdinamento
        Case 1
          Return _
            m_cilindrata.CompareTo(temp.cilindrata)
        Case 2
          Return _
            m_targa.CompareTo(temp.targa)
        Case 3
          Return _
            m_marca.CompareTo(temp.marca)
      End Select
    End If

    Throw New ArgumentException("Oggetto " & _
                  "di tipo diverso da Auto")
  End Function

  ReadOnly Property cilindrata() As Integer
    Get
      cilindrata = m_cilindrata
      Exit Property
    End Get
  End Property

  ReadOnly Property targa() As String
    Get
      targa = m_targa
      Exit Property
    End Get
  End Property

  ReadOnly Property marca() As String
    Get
      marca = m_marca
      Exit Property
    End Get
  End Property

  WriteOnly Property tipoOrdinamento() As String
    Set(ByVal value As String)
      ' 1 = cilindrata
      ' 2 = targa
      ' 3 = marca
      m_tipoOrdinamento = value
      Exit Property
    End Set
  End Property
End Class

